<template>
  <el-dialog
    title="关联项目"
    :visible.sync="dialogValue"
    width="1200px"
  >
    <div class="f-r a-c j-b">
      <el-form inline label-width="90px">
        <el-form-item label="项目名称：">
          <el-input clearable v-model="searchParams.projectName" />
        </el-form-item>
        <el-form-item label="项目类型：">
          <el-input clearable v-model="searchParams.projectType">
          </el-input>
        </el-form-item>
        <el-form-item label="项目类别：">
          <el-input clearable v-model="searchParams.projectCategory">
          </el-input>
        </el-form-item>
        <el-form-item label="地区：">
          <el-input clearable v-model="searchParams.area" />
        </el-form-item>
        <el-form-item label="所属行业：">
          <el-input clearable v-model="searchParams.industryName"/>
        </el-form-item>
        <el-form-item label="实施单位：">
          <el-input clearable v-model="searchParams.projectUnit" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-box">
      <el-table
        ref="project2TableRef"
        v-loading="loading"
        height="400px"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="80px">
          <template slot-scope="scope">
            <el-button type="text" @click="onRel(scope.row)">关联</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import { area_list, http_project1, http_project2 } from '@/api'
import { deepClone } from '@/utils'

export default {
  name: 'User1Add',
  mixins: [crud],
  data() {
    return {
      request: http_project2,
      searchParams: {
        projectName: '',
        projectType: '',
        projectCategory: '',
        area: '',
        industryName: '',
        projectUnit: '',
      },
      options1: [
      ],
      options2: [
        { value: 0, name: '进行中' },
        { value: 1, name: '已完成' },
        { value: 2, name: '未完成' }
      ],
      options3: [
        { value: 0, name: '未关联' },
        { value: 1, name: '已关联' }
      ],
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'projectType', label: '项目类型' },
        { prop: 'projectCategory', label: '项目类别' },
        { prop: 'projectNature', label: '项目性质' },
        { prop: 'industryName', label: '所属行业' },
        { prop: 'area', label: '地区' },
        { prop: 'totalAmount', label: '总投资' },
          { prop: 'implementUnit', label: '实施单位' },
          { prop: 'progressName', label: '当前进度' },
      ],
      tableData: [],
      projectId: ''
    }
  },
  created() {

  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.progressName = this.options2.find(item => item.value == el.progress)?.name
      })

      this.$nextTick(() => {
        this.$refs.project2TableRef.doLayout()
      })
    },
    open(item) {
      this.projectId = item.id
      this.dialogValue = true
      this.onSearch()
    },
    onRel(row) {
      http_project1.rel({
        id: this.projectId,
        relevanceId: row.id
      }).then(res => {
        this.$message.success(res.msg)
        this.dialogValue = false
        this.$emit('get-page')
      })
    }
  }
}
</script>
